package cn.selfiot.iotman.view.editor;

import cn.selfiot.iotman.core.I18N;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.layout.VBox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ResourceBundle;

/**
 * Json编辑器
 *
 * @author hugo
 * @since 2020/8/5
 */
public class JsonEditor extends VBox {
    private static final Logger LOGGER = LoggerFactory.getLogger(JsonEditor.class);
    
    private JsonEditorController controller;
    
    public JsonEditor() {
        super();
        String fxml = EditorConstants.FXML;
        String style = EditorConstants.STYLE;
        String bundleName = EditorConstants.BUNDLE;
        try {
            ResourceBundle bundle = I18N.getBundle(bundleName);
            FXMLLoader loader = new FXMLLoader(getClass().getResource(fxml), bundle);
            Node node = loader.load();
            node.getStyleClass().add(style);
            this.getChildren().add(node);
            
            controller = loader.getController();
        } catch (Exception e) {
            LOGGER.error(e.getMessage());
        }
    }
    
    public void setOnlyEditor() {
        controller.setOnlyEditor();
    }
    
    public JsonEditorController getController() {
        return controller;
    }
    
    public void setController(JsonEditorController controller) {
        this.controller = controller;
    }
}
